//
//  TabBarViewCtrlConfig.m
//  test
//
//  Created by Zhuangyh on 16/1/29.
//  Copyright © 2016年 jaga. All rights reserved.
//

#import "TabBarViewCtrlConfig.h"
#import "ViewController.h"
#import "DYNavigationController.h"
@interface TabBarViewCtrlConfig ()
@property(nonatomic,readwrite,strong)CYLTabBarController *tabBarController;//只是为了解决readonly导致的无法访问的问题
@end

@implementation TabBarViewCtrlConfig

+ (TabBarViewCtrlConfig *)shareConFig; {
    static TabBarViewCtrlConfig *TabBarViewCtrlConfig_share;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        TabBarViewCtrlConfig_share = [[TabBarViewCtrlConfig alloc] init];
    });
    return TabBarViewCtrlConfig_share;
}

- (CYLTabBarController *)tabBarController {
    
    if (!_tabBarController) {
        ViewController *firstViewController = [[ViewController alloc] init];
        DYNavigationController *firstNavigationController = [[DYNavigationController alloc]
                                                       initWithRootViewController:firstViewController];
        firstNavigationController.navigationBar.translucent = NO;
        
        
        UIViewController *secondViewController = [[UIViewController alloc] init];
        UIViewController *secondNavigationController = [[UINavigationController alloc]
                                                        initWithRootViewController:secondViewController];
        
        
        ViewController *vc3 = [[ViewController alloc] init];
        ViewController *vc4 = [[ViewController alloc] init];
       
        CYLTabBarController *tabBarController = [[CYLTabBarController alloc] init];
        [self customizeTabBarForController:tabBarController];
        [tabBarController setViewControllers:@[
                                               firstNavigationController,
                                               secondNavigationController,
                                               vc3,
                                               vc4
                                               ]];
        _tabBarController = tabBarController;
    }
    return _tabBarController;
}

- (void)customizeTabBarForController:(CYLTabBarController *)tabBarController {
    
    //更换 TabBar 自带的顶部阴影
    [[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"tapbar_top_line"]];

    NSDictionary *dict1 = @{
                            CYLTabBarItemTitle : @"首页",
                            CYLTabBarItemImage : @"home_normal",
                            CYLTabBarItemSelectedImage : @"home_highlight",
                            };
    NSDictionary *dict2 = @{
                            CYLTabBarItemTitle : @"同城2",
                            CYLTabBarItemImage : @"mycity_normal",
                            CYLTabBarItemSelectedImage : @"mycity_highlight",
                            };
    NSDictionary *dict3 = @{
                            CYLTabBarItemTitle : @"消息",
                            CYLTabBarItemImage : @"message_normal",
                            CYLTabBarItemSelectedImage : @"message_highlight",
                            };
    NSDictionary *dict4 = @{
                            CYLTabBarItemTitle : @"我的",
                            CYLTabBarItemImage : @"account_normal",
                            CYLTabBarItemSelectedImage : @"account_highlight"
                            };
    NSArray *tabBarItemsAttributes = @[
                                       dict1,
                                       dict2,
                                       dict3,
                                       dict4
                                       ];
    tabBarController.tabBarItemsAttributes = tabBarItemsAttributes;
}

@end
